// UserController.java
package org.example.data_work_demo1.controller;

import org.example.data_work_demo1.model.User;
import org.example.data_work_demo1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    // 用户注册 (POST请求示例)
    @PostMapping("/register")
    public void registerUser(@RequestBody User user) {
        userService.registerUser(user);
    }

    // 用户登录 (POST请求示例)
    @PostMapping("/login")
    public User loginUser(@RequestParam String username, @RequestParam String password) {
        return userService.loginUser(username, password);
    }

    // 修改密码 (PUT请求示例)
    @PutMapping("/change-password")
    public void changePassword(@RequestParam Integer userId, @RequestParam String newPassword) {
        userService.changePassword(userId, newPassword);
    }

    // 获取用户信息 (GET请求示例)
    @GetMapping("/{userId}")
    public User getUserInfo(@PathVariable Integer userId) {
        return userService.getUserInfo(userId); // 需要在UserService中添加getUserInfo方法
    }

    // 更新用户信息 (PUT请求示例)
    @PutMapping
    public void updateUser(@RequestBody User user) {
        userService.updateUser(user);
    }
}
